<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<form>
    <h1 id="alert"></h1>
    用户名：<input name="uname"><br>
    密码：<input type="password" name="pass"><br>
    <a href="regist.html">一秒钟快速注册</a>
    <input type="button" value="登陆" onclick="login()">
</form>
<script>
    function login(){
        var al = document.getElementById("alert");

        if(hasUser()){
            location.href= "edit_user.html";
//            登陆成功
        }else{
            al.innerHTML = "登陆失败，用户名或密码不存在";
//            登陆失败
        }
    }

    function hasUser(){
        var form1 = document.forms[0];
        var User = {
            name : form1.uname.value.trim(),
            pass : form1.pass.value.trim()
        }
        var users = localStorage.getItem("users");
        if(!users)return false;
        users = JSON.parse(users);
        if(!Array.isArray(users))return false;
        if(users.length<1)return false;
        return users.some(function(item){
            return item.name==User.name&&item.pass == User.pass;
        });

    }
</script>
</body>
</html>